package com.bf.electroplating.config;


import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("My API")
                        .description("API Documentation with Bearer Token and Tenant ID")
                        .version("1.0.0"))
                .components(new Components()
                        // Bearer Token 认证配置
                        .addSecuritySchemes("bearerAuth",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")
                                        .description("输入 Bearer Token 进行认证")
                        )
                        // tenantId 作为额外的头参数
                        .addSecuritySchemes("token",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.APIKEY)
                                        .name("token")
                                        .in(SecurityScheme.In.HEADER)
                                        .description("输入 Tenant ID 标识多租户环境")
                        )
                )
                // 全局启用这两个安全项
                .addSecurityItem(new SecurityRequirement()
                        .addList("bearerAuth")
                        .addList("token"));
    }
}

